package com.liruo.enumconverter.test.web.config;

import com.google.gson.Gson;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:liruo
 * @Date:2023-02-26-15:38:10
 * @Desc
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private Gson gson;
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        List<HttpMessageConverter<?>> httpMessageConverters = new ArrayList<>();
        httpMessageConverters.add(new GsonHttpMessageConverter(gson));
        httpMessageConverters.addAll(converters);
        converters.clear();
        converters.addAll(httpMessageConverters);
    }
}
